package com.zc.app.shiro.controller;

import com.zc.app.shiro.peer.ResourcePeer;
import com.zc.app.shiro.peer.UserPeer;
import com.zc.app.shiro.service.ResourceService;
import com.zc.app.shiro.service.UserService;
import com.zc.app.shiro.utils.JsonUtils;
import com.zc.app.sys.dao.peer.SystemUserPeer;
import com.zc.app.sys.service.SystemUserService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.zc.app.shiro.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Set;

/**
 * <p>User: Zhang Kaitao
 * <p>Date: 14-2-14
 * <p>Version: 1.0
 */
@Controller
public class IndexController {

    private static Logger logger = LogManager.getLogger(IndexController.class);
//    @Autowired
//    private ResourceService resourceService;
//    @Autowired
//    private UserService userService;

    @Autowired
    private SystemUserService systemUserService;

    @RequestMapping("/main")
    public String main(@CurrentUser UserPeer loginUser, Model model) throws IOException {

        //查看上下文中是否该用户已经登录了
        SystemUserPeer user = systemUserService.getCurrentUser();
        //如果已经登录，则跳转到管理首页
        if(user.getAccountId() != null){
            model.addAttribute("currentUser", user.getLoginName());
            return "main";
        } else {
            return "forward:/login";
        }
    }


    @RequestMapping("/welcome")
    public String welcome() {
        return "welcome";
    }


}
